package com.shujia.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.params.SetParams;

public class RedisApi {
    public static void main(String[] args) {

        //1、创建链接
        Jedis jedis = new Jedis("master", 6379);


        //指定密码
        jedis.auth("123456");

        //2、增删改查数据
        jedis.set("001", "java");

        String s = jedis.get("001");
        System.out.println(s);


        jedis.close();

    }

    Jedis jedis;

    @Before
    public void init() {

        //1、创建链接
        jedis = new Jedis("master", 6379);

    }


    @Test
    public void set() {
        //增加ttl
        SetParams ex = SetParams.setParams().ex(5);

        jedis.set("002", "spark", ex);
    }


    @Test
    public void get() {
        String s = jedis.get("002");
        System.out.println(s);
    }

    @After
    public void close() {
        jedis.close();
    }

}
